<!DOCTYPE HTML>
<html lang="zh-CN"><head>
	<title>开始众筹</title>
	<meta charset="UTF-8">
	<meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=no">
	<link href="{$Think.config.RESOURCEURL}wx_assets/micontent/materiaDetail.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
	<link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
	<link href="{$Think.config.RESOURCEURL}wx_assets/dist/gmu.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
	<link href="{$Think.config.RESOURCEURL}wx_assets/css/product/product_detail.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
	<if condition="$mallHue.mallHue eq '1'">
		<link href="{$Think.config.RESOURCEURL}wx_assets/css/product/crowdfunding_stall_blue.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
		<else/>
		<link href="{$Think.config.RESOURCEURL}wx_assets/css/product/crowdfunding_stall.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
	</if>
	<link href="{$Think.config.RESOURCEURL}wx_assets/css/iconfont/font_tuan.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
	<!-- <script src="http://sdk.talkingdata.com/app/h5/v1?appid=DE13C350F41F5DE78FEC51DB5DE730D1&vn=v2&vc=v2"></script> -->
	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/dist/gmu.min.js{$Think.config.RESOURCE_VER}"></script>
	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js{$Think.config.RESOURCE_VER}"></script>
	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}"></script>
	<script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
</head>
<body>
<!--关注浮层 begin-->
<!--0表示未关注，1表示已关注-->
<if condition="$subscribe eq '0'">
	<div class="careview">
		<img src="{$mall.logo}" alt="" />
		<a href='{$mall.wechaturl}'>立即关注</a>
		<empty name="mall.recommend">
			<p>{$mall.wechatname}</p>
			<else />
			<p>{$mall.recommend}</p>
		</empty>

		<span></span>
	</div>
	<script>
		function closePlayMsgView(){
			$('.play_msg').hide();
		}
		$(function(){
			var isfirst=getCookie('new_detail');
			if(isfirst!=1)
			{
				$('.play_msg').show();
				setCookie("new_detail","1");
			}

		})
		$('.careview > span').on('click',function(){
			$('.careview').hide();
		});
	</script>
</if>
<div class="container">
	<div class="h1">选择回报</div>
	<volist name="stallList" id="stall">
		<if condition="($stall['restrictPerson'] eq '1' and $stall['surplusPerson'] elt 0) or ($stall['restrictAmount'] eq '1' and $stall['surplusAmount'] elt 0)">
			<div class="crowdStall disabled" data-name="{$stall.firstSpecificName}">
			<else/>
			<div class="crowdStall" data-name="{$stall.firstSpecificName}">
		</if>
			<div class="stall">
				<if condition="$stall['maxDisPrice'] neq '' and $stall['maxDisPrice'] gt 0 and $stall['maxDisPrice'] neq $stall['minDisPrice']">
					<div class="money">支持：￥{$stall.minDisPrice}~{$stall.maxDisPrice}</div>
					<elseif condition="$stall['maxDisPrice'] neq '' and $stall['maxDisPrice'] gt 0"/>
					<div class="money">支持：￥{$stall.minDisPrice}</div>
					<elseif condition="$stall['maxFixedPrice'] neq $stall['minFixedPrice']"/>
					<div class="money">支持：￥{$stall.minFixedPrice}~{$stall.maxFixedPrice}</div>
					<else/>
					<div class="money">支持：￥{$stall.minFixedPrice}</div>
				</if>
				<if condition="$stall['drawStall'] eq '1'">
					<a class="tag">抽奖</a>
				</if>
				<div class="support"><span>{$stall.supportPerson}</span> 位支持者
					<if condition="$stall['restrictAmount'] eq '1'">
						（剩余 <span>{$stall.surplusAmount}</span> 份）
					</if>
				</div>
				<if condition="($stall['restrictPerson'] eq '1' and $stall['surplusPerson'] elt 0) or ($stall['restrictAmount'] eq '1' and $stall['surplusAmount'] elt 0)">
					<span class="radio full">限额已满</span>
					<else/>
					<i class="iconfont radio">&#xe660;</i>
				</if>

			</div>
			<div class="description">
				{$stall.stallDescribe}
				<if condition="$stall['firstSpecificUrl'] neq ''">
					<img src="{$stall.firstSpecificUrl}">
				</if>
			</div>
		</div>
	</volist>
</div>
<div class="menu">
	<a onclick="javascript:history.back(-1);"><i class="iconfont">&#xe62a;</i><span>返回</span></a>
	<if condition="$productInfo.crowdStatus gt 1">
		<a  class="disabled">去支持</a>
		<else/>
		<a id="buy">去支持</a>
	</if>

</div>
<div class="productInfo" id="productInfo" style="z-index:100">
	<div class="main">
		<div class="info">
			<div class="closeDiv"><div class="close" id="close"></div></div>
			<div class="imgDiv" align="center">
				<volist name="productInfo.picUrl1" id="picItem">
					<if condition="$i eq '2'">
						<img class="default" src="{$picItem.picUrl}">
					</if>
				</volist>
			</div>
			<div class="p-name">
				<div class="title">
					<span>众筹</span>
					{$productInfo.name}
				</div>
				<div class="price" style="overflow: hidden;height: 26px;">
					<div style="float: left;" id="buyPrice">
						<if condition="$productInfo['supportSpecification'] eq '1'">
							<if condition="$productInfo['maxDisPrice'] neq '' and $productInfo['maxDisPrice'] gt 0 and $productInfo['maxDisPrice'] neq $productInfo['minDisPrice']">
								￥{$productInfo.minDisPrice}~{$productInfo.maxDisPrice}
								<elseif condition="$productInfo['maxDisPrice'] neq '' and $productInfo['maxDisPrice'] gt 0"/>
								￥{$productInfo.minDisPrice}
								<elseif condition="$productInfo['maxFixedPrice'] neq $productInfo['minFixedPrice']"/>
								￥{$productInfo.minFixedPrice}~{$productInfo.maxFixedPrice}
								<else/>
								￥{$productInfo.minFixedPrice}
							</if>
							<else/>
							<if condition="$productInfo['discountedPrice'] neq '' and $productInfo['discountedPrice'] gt 0">
								￥{$productInfo.discountedPrice}
								<else/>
								￥{$productInfo.fixedPrice}
							</if>
						</if>
					</div>
				</div>
			</div>
		</div>
		<if condition="$customized neq ''">
			<div style="max-height:250px;overflow-y: scroll;">
				<else/>
				<div style="max-height:250px;">
		</if>
		<if condition="$productInfo['supportSpecification'] eq '1' and $color neq ''">
			<div class="mod_property" id="prop-list">
				<dl>
					<dt>{$colorUnit}</dt>
					<volist name="color" id="colorVal">
						<if condition="$colorurl[$i] neq ''">
							<dd data-name="{$colorVal}" style="vertical-align: top;"><img src="{$colorurl[$i]}"/><label>{$colorVal}</label></dd>
							<else/>
							<dd data-name="{$colorVal}" style="vertical-align: top;"><label style="float:none">{$colorVal}</label></dd>
						</if>
					</volist>
				</dl>
			</div>
		</if>
		<div class="buyNum">
			<div class="title">购买数量</div>
			<div class="numDiv">
				<a class="sub disabled" tag="sub" id="sub"></a>
				<input type="number" min="1" max="10000" step="1" value="1" class="num" id="buyNum"/>
				<if condition="$productInfo.inventory eq '1' AND $productInfo.supportSpecification eq '0' AND $productInfo.inventoryCount lt 2">
					<a class="plus disabled" tag="add" id="plus1"></a>
					<else/>
					<a class="plus" tag="add" id="plus"></a>
				</if>

			</div>
			<notempty name="productInfo.inventory">
				<if condition="$productInfo.supportSpecification eq '0' AND $productInfo.inventoryCount gt 0">
					<span class="inventory" id="inventory_count" style='display:block'>&nbsp;剩余<span id="stock-num">{$productInfo.inventoryCount}</span>件</span>
					<else/>
					<span class="inventory" id="inventory_count" style="display:none">&nbsp;剩余<span id="stock-num">{$productInfo.inventoryCount}</span>件</span>
				</if>
			</notempty>
		</div>
	</div>
</div>
<if condition="$inventory neq '' AND $supportSpecification eq '0' AND $inventoryCount eq ''">
	<div class="beSure btn_disabled">确定</div>
	<else/>
	<div class="beSure">确定</div>
</if>
</div>
<a id="car" class="car" onclick="detail.goCart()">
	<i class="iconfont">&#xe608;</i>
		<span>
			<p id="carNum"></p>
		</span>
</a>
<input type="hidden" id="shareImg" value="<php>echo $productInfo['picUrl1'][1]['picUrl'];</php>">
<script type="text/javascript">
	var baseUrl = '{$Think.config.SERVER_HOST}';
	var hrefPath = baseUrl+'call.html?customerId={$customerId}';
	var basePath = baseUrl+'call.json?customerId={$customerId}&userName={$userName}';
	var p=$.util.getParamAsObject();
	var buyParams={
		"pids": "{$productInfo['id']}",
		"type": "buy",
		"qId":p.qId||"{$quanInfo.qId}",
		"miUId":p.miUId||"{$quanInfo.uId}",
		"vId":"{$productInfo['vId']}",
		"shareId":"{$productInfo['sId']}",
		"shareFromGuid":p.fromGuid,
		"userName":'{$userName}',
		"visitId":p.visitId,
		"distributionId":{$productInfo['distributionId']},
		"proSource":"{$productInfo['proSource']}"
	};
	var detail={
		cartList:null,//购物车详情
		guid:"{$guid}",
		init:function(){
			$("#productInfo").css("bottom",($("#productInfo").height()+50)*-1);
			this._initEvent();
			this.getCartGoodsNum();
		},
		_initEvent:function(){
			var me = this;
			$(".crowdStall").click(function(){
				if($(this).hasClass("disabled")){return;}
				$("#buyNum").val(1);
				$(this).addClass("current").siblings(".current").removeClass("current").find(".radio").html("&#xe660;");
				$(this).find(".radio").html("&#xe636;");
				me.checkSpe();
			});
			$("#buy").click(function(){
				if($(".crowdStall.current").length<=0){
					$.util.showMsg("请选择回报！");
					return;
				}

				$("#productInfo").css("bottom",0);
			});
			$("#close").click(function(){
				$("#productInfo").css("bottom",($("#productInfo").height()+50)*-1);
				$("#buyNum").val(1);
			});
			$("#prop-list dd").click(function(){
				$(this).addClass("current").siblings("dd.current").removeClass("current");
				$("#buyNum").val(1);
				me.checkSpe();
			});
			$(".sub,.plus").on("click", function(e) {
				me._initBuyNum(e);
			});
			$(".beSure").click(function(){
				me._initBuy(this);
			});
		},
		_initBuy:function(ctrl){
			var me = this;
			var p=$.util.getParamAsObject();
			var colors='';
			var sizes = '';
			if (!$(ctrl).hasClass("btn_disabled")) {
				if($(".crowdStall").length>0){
					sizes = $(".crowdStall.current").data("name");
					if(!sizes){
						$.util.alert('请选择档位!');
						return;
					}
				}
				if($("#prop-list").length>0){
					colors = $("#prop-list dd.current").data("name");
					if(!colors){
						$.util.alert('请选择' + $("#prop-list dt").text());
						return;
					}
				}
				if ($("#stock-num") &&$("#stock-num").html()&& $("#stock-num").html() <= 0) {
					$.util.alert("库存不足");
					return;
				}
				var params = {
					"pids":'{$id}',
					"sizes": sizes,
					"colors": colors,
					"counts": $("#buyNum").val(),
					"type":"buy"
				};
				if(window.buyParams) {
					params = $.extend(params, window.buyParams);
				}
				$(ctrl).addClass("btn_disabled");
				$.util.pageLoading.show();
				$.req.get("call.json?customerId={$customerId}&module=product&method=preSubmitOrder", {
					params: params
				}, function (data) {

					if (data.hasOwnProperty('code')) {
						$(ctrl).removeClass("btn_disabled");
						$.util.showMsg(data.msg);
						$.util.pageLoading.hide();
					} else {
						var p = {
							"tplid": 1,
							"id": data.id
						};
						location.href = window.hrefPath + '&module=product&method=getOrderDetail&force=1&params=' + encodeURIComponent(JSON.stringify(p));
					}
				});
			}
		},
		selectedSpec:function(){
			var size = '{$size}';
			var color = '{$color}';
			if(size&&$(".crowdStall.current").length<=0){
				return false;
			}
			if(color&&$("#prop-list dd.current").length<=0){
				return false;
			}
			return true;
		},
		_initBuyNum: function(e) {
			var me=this;
			var buyNum = $("#buyNum"),
					target = $(e.target),
					type = target.attr("tag"),
					num = 1 * buyNum.val();
			if (target.hasClass("disabled")) {
				return;
			}
			if (num) {
				if (isNaN(num)) {
					buyNum.val(1);
				} else {
					var ktotal = $("#stock-num").html() || 999;
					if(!me.selectedSpec()){
						return;
					}
					if (type == "add") {
						buyNum.val(++num);
						$("#sub").removeClass("disabled");
						if(num>=ktotal){
							$("#plus").addClass("disabled");
						}
					} else {
						if (num > 1) {
							buyNum.val(--num);
							$("#plus").removeClass("disabled");
							if (num < 2) {
								$("#sub").addClass("disabled");
							}
						}
					}
				}
			}
		},
		checkSpe:function(){
			var availSku = JSON.parse('{$availSku}');
			var inventory = '{$productInfo.inventory}';
			var size = '{$size}';
			var color='{$color}';
			var stallList = JSON.parse('{$stallJson}');
			var index = $(".crowdStall.current").index();
			var stall = stallList[--index];
			var sizeVal = $(".crowdStall.current").data("name");
			var key = '';
			if(size.length>0){
				key+=sizeVal;
			}
			if(color&&color.length>0){
				var colorVal = $("#prop-list dd.current").data("name");
				key += "|" + colorVal;
			}
			if ((color && !colorVal)||!availSku[key])return;
			var fixedPrice = parseFloat(availSku[key].fixedPrice);
			var discountedPrice = parseFloat(availSku[key].discountedPrice);
			var stockCount = parseInt(availSku[key].inventoryCount);
			if(stall.restrictPerson==1&&stall.surplusPerson<stockCount){
				stockCount = stall.surplusPerson;
			}
			if(stall.restrictAmount==1&&stall.surplusAmount<stockCount){
				stockCount = stall.surplusAmount;
			}
			if (discountedPrice > 0) {
				$("#buyPrice").html("￥" + discountedPrice);
			} else {
				$("#buyPrice").html("￥" + fixedPrice);
			}
			if (parseInt(inventory)||stall.restrictAmount==1||stall.restrictPerson==1) {
				if (stockCount <= 0) {
					$(".soldOut").show();
					$(".beSure").addClass("btn_disabled");
				} else {
					$(".soldOut").hide();
					$(".beSure").removeClass("btn_disabled");
				}
				$("#inventory_count").show();
				$("#stock-num").html(stockCount);
				var nowNum = parseInt($("#buyNum").val());
				if (nowNum >= stockCount) {
					$("#plus").addClass("disabled");
				} else {
					$("#plus").removeClass("disabled");
				}
				if (nowNum < 2) {
					$("#sub").addClass("disabled");
				}
			}
		},
		getCartGoodsNum:function () {
			var me = this;
			var customerId=$.util.getParam("customerId");
			$.req.get("call.json?module=product&customerId="+customerId+"&method=getCarNum",{
				params:{
					"type":"buy",
					"sid":"-1"
				}
			},function(data){
				if (!data.code) {
					$("#carNum").text(data.total || 0).data("num", data.total);
					detail.cartList = data.list;
					if (data && data.total > 0) {
						$("#car").addClass("to-car");
					} else {
						$("#car").removeClass("to-car");
					}
				}
			});
		},
		getShareUrl:function(){
			var p=$.util.getParamAsObject();
			var shareUrl="";
			var me=this;
			var mallQId = "{$quanInfo.qId}";
			var mallUId = "{$quanInfo.uId}";
			if(p.qId||(mallQId&&mallUId)){
				var params={
					"id":"{$productInfo.id}",
					"fromUserName":"{$userName}",
					"qId":p.qId||mallQId,
					"miUId":p.miUId||mallUId
				}
			}else{
				var params={
					"id":"{$productInfo.id}",
					"fromUserName":"{$userName}"
				}
			}
			params=encodeURIComponent(JSON.stringify(params));
			shareUrl=baseUrl+'call.html?customerId={$customerId}&module=product&method=getProduct&params='+params;
			return shareUrl;
		},
		goCart:function(){
			var p=$.util.getParamAsObject();
			var params=$.extend(p,{
				"sid":"-1",
				"type":"buy",
				"tplid":"4",
				"mid":4,
				"vId":"{$productInfo['vId']}",
				"qId":p.qId||"{$quanInfo.qId}",
				"miUId":p.miUId||"{$quanInfo.miUId}"
			});
			params=encodeURIComponent(JSON.stringify(params));
			location.href = 'call.html?customerId={$customerId}&module=product&method=getCart&params=' + params;
		}

	}
	detail.init();
	var shareUrl=detail.getShareUrl();
	wx_share.init({
		"title":"{$productInfo.title}",
		"desc":'{$productInfo.recommend}',
		"link":shareUrl,
		"imgUrl": $.trim($("#shareImg").val()),
		"pkg":{
			"appId": '{$pkg.appId}',
			"timestamp": '{$pkg.timestamp}',
			"nonceStr": '{$pkg.nonceStr}',
			"signature": '{$pkg.signature}'
		},
		success:function(config,shareType){
			var p=$.util.getParamAsObject();
			$.req.get("call.json?customerId={$customerId}&module=quan&method=saveShare",{
				params:{
					"qId":p.qId,
					"sId":"{$sId}",
					"guid":detail.guid,
					"fromGuid":p.fromGuid || "",
					"miUId":p.miUId,
					"shareType":shareType,
					"fromPage":"product_detail"
				}
			},function(data){
				if(data && !data.code){
					detail.guid=data.guid;
				}
			});
		}
	});
	var showImg=function(){

		$('.comnt-img').each(function(){
			var imgs=new Array;
			$(this).children().each(function(){
				var _index=$(this).find('img').attr('src').split('@')[0];
				imgs.push(_index);
			})
			$(this).children().unbind('click');
			$(this).children().click(function(){
				var activeImg=$(this).find('img').attr('src').split('@')[0];
				wx_share.showImg(imgs,activeImg);
			})
		});
	}


</script>
</body></html>
